var CID = '500000',
	price1 = 48,
	price2 = 59,
	CAPI = 'http://pb1.fcbird.org/',
	CAPI1 = 'http://pb1.fcbird.org/',
	CAPI2 = 'http://pb1.fcbird.org/';
window.top !== window.self && (window.top.location = window.location);

function gq(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null
}
function sc(o, t, i) {
	i = i || "d1";
	var a = getsec(i),
		n = new Date;
	n.setTime(n.getTime() + 1 * a), document.cookie = o + "=" + escape(t) + ";expires=" + n.toGMTString()
}
function gc(o) {
	var t, i = new RegExp("(^| )" + o + "=([^;]*)(;|$)");
	var v = (t = document.cookie.match(i)) ? t[2] : null;
	if (v) v = unescape(v);
	return v
}
function cc() {
	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if (keys) {
		for (var i = keys.length; i--;) document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
	}
}
function isv(k) {
	return gc(k) == 1
}
if (gq("c")) {
	CID = gq("c");
	if (gc('CID') && CID != gc('CID')) cc();
	sc('CID', gq("c"), "d30")
} else if (gc('CID')) {
	CID = gc('CID')
}
if (gq("f")) sc('ios', 1, "d30");
var browser = {
	versions: function() {
		var o = navigator.userAgent;
		navigator.appVersion;
		return {
			mobile: !! o.match(/AppleWebKit.*Mobile/i) || !! o.match(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/),
			mac: o.indexOf("Mac") > -1,
			ios: !! o.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
			android: o.indexOf("Android") > -1 || o.indexOf("Linux") > -1,
			weixin: !! o.match(/MicroMessenger/i),
			qq: ( !! o.match(/QQ/i) && ( !! o.match(/NetType/i) || !! o.match(/Pixel/i)))
		}
	}(),
	language: (navigator.browserLanguage || navigator.language).toLowerCase()
};
(function(window) {
	var u = {};
	u.jsonToStr = function(json) {
		if (typeof json === 'object') {
			return JSON && JSON.stringify(json)
		}
	};
	u.strToJson = function(str) {
		if (typeof str === 'string') {
			return JSON && JSON.parse(str)
		}
	};
	u.rand = function(n, m) {
		if (!m) m = n, n = 0;
		var w = m - n;
		Math.random() * w;
		Math.random() * w + n;
		return Math.round(Math.random() * w + n)
	};
	window.$api = u
})(window);

function play(o, t) {
	var trytime = gc("x_a_watch") || 0;
	trytime++;
	sc("x_a_watch", trytime);
	if (9 > trytime || isv('vip')) {
		if (isv('ios')) {
			if (isv('vip')) {
				window.location.href = "syios://play$" + t + "#0"
			} else {
				var _video = gettry();
				window.location.href = "syios://play$" + _video + "#20"
			}
			return
		}
		try {
			if (isv('vip')) {
				try {
					window.wst.start()
				} catch (e) {}
				window.wst.
				function(t, 0)
			} else {
				var _video = gettry();
				window.wst.
				function(_video, 20)
			}
		} catch (e) {
			window.location.href = "./play.html?title=" + escape(o) + "&mp4=" + t + "&cop=" + CID
		}
	} else {
		pay()
	}
}
function pay() {
	var o = $("#paybox").dialog("show");
	o.on("dialog:action", function(o) {
		1 == o.index && (window.location.href = "./check.html?c=" + CID + "&r=" + Math.random())
	})
}
function pay2() {
	var dia = $.dialog({
		title: '\u6e29\u99a8\u63d0\u793a',
		content: '\u975e\u4f1a\u5458\u53ea\u80fd\u89c2\u770b\u0032\u0030\u79d2\u54e6\u007e',
		button: ["\u7b49\u4e0b\u5145", "\u53bb\u5145\u503c"]
	});
	dia.on("dialog:action", function(e) {
		if (e.index == 0) {
			if (stop && isv('an')) Player.play()
		} else {
			window.location.href = "./check.html?c=" + CID + "&r=" + Math.random()
		}
	})
}
function getNo() {
	if (1 == Math.floor(2 * Math.random() + 1)) {
		var o = "x_a_no",
			t = 3985,
			i = gc(o);
		i ? (_ckno = parseInt(i) + 1, sc(o, _ckno, "d30")) : sc(o, t, "d30"), i = i ? _ckno : t;
		$("#showno").html(i);
		$(".ui-newstips-wrap").show().addClass("flip-top");
		setTimeout(function() {
			$(".ui-newstips-wrap").hide()
		}, 5e3)
	}
}
function getsec(o) {
	var t = 1 * o.substring(1, o.length),
		i = o.substring(0, 1);
	return "s" == i ? 1e3 * t : "h" == i ? 60 * t * 60 * 1e3 : "d" == i ? 24 * t * 60 * 60 * 1e3 : void 0
}
if (showjs) {
	var dataurl = "//img.fcbird.org/20001/data/" + cid + ".json";
	var vlist = new Vue({
		el: "body",
		data: {
			slider: [],
			data: []
		},
		methods: {
			play: function(o, t) {
				play(o, t)
			}
		},
		ready: function() {
			var o = this;
			$.ajax({
				type: "get",
				async: true,
				cache: true,
				url: dataurl,
				dataType: "jsonp",
				timeout: 90000,
				jsonpCallback: 'jsonp',
				success: function(json) {
					var t = json[0];
					o.picurl = t.picurl || '';
					o.data = t.data;
					o.slider = t.slider
				}
			})
		}
	})
}
function gettry() {
	var vlist = gc('vlist');
	if (vlist) vlist = $api.strToJson(vlist);
	if (vlist && vlist.length > 0) {
		var k = $api.rand(vlist.length - 1);
		var url = vlist[k].mp4;
		vlist.splice(k, 1);
		sc("vlist", $api.jsonToStr(vlist));
		try {
			window.wst.start()
		} catch (e) {}
		return url
	}
	var dataurl = "//img.fcbird.org/20001/data/v.json";
	$.ajax({
		type: "get",
		async: true,
		url: dataurl,
		dataType: "jsonp",
		timeout: 90000,
		jsonpCallback: 'jsonp',
		success: function(json) {
			var t = json[0];
			sc("vlist", $api.jsonToStr(t.data))
		}
	});
	var i = $api.rand(5) + 1;
	return 'http://vod1.fcbird.org/try/20s_' + i + '.mp4'
}
function alertmsg(_msg) {
	try {
		window.wst.alert(_msg)
	} catch (e) {}
}
function goback() {
	window.location.href = "./index.html?c=" + CID
}
function load_paylink(_cid) {
	_cid = _cid || CID;
	CID = _cid;
	sc('CID', CID, "d30");
	sc('an', 1, "d30")
}
function payopen(topay) {
	if (isv('vip')) return;
	if (topay) window.location.href = "./check.html?c=" + CID + "&r=" + Math.random();
	else pay2()
}
var _page = window.location.pathname.replace(window.location.search, '');
if (_page == "/play.html") {
	if (!isv('vip')) {
		vl = gettry()
	}
	var _tp = '<div style="text-align:center;margin-top:10px;color:#eee">\u975e\u4f1a\u5458\u53ea\u80fd\u8bd5\u770b\u0032\u0030\u79d2\uff0c<a href="./check.html?c=' + CID + '&r=' + Math.random() + '">\u6210\u4e3a\u4f1a\u5458</a>\u89c2\u770b\u5168\u90e8</div>';
	var playbox = $("#playbox");
	if (!isv('vip')) $(_tp).appendTo(playbox);
	$('<video autoplay="autoplay" preload="auto" id="player" controls="false" poster="http://img.fcbird.org/20001/static/images/player2.png"><source id="source1" src="' + vl + '" type="video/mp4"></source></video>').appendTo(playbox);
	if (!isv('vip')) $(_tp).appendTo(playbox);
	var doplay = function() {
			var trytime = gc("x_a_watch") || 0;
			if (9 > trytime && !_ispay && !isv('vip')) {
				setTimeout(gopay, 18000)
			} else {
				if (!isv('vip')) payout();
				try {
					window.wst.start()
				} catch (e) {}
			}
		};
	Player = document.getElementById("player");
	var _ispay = isv('vip');
	var mainheight = $(window).height() - 220;
	var mainwidth = $(window).width();
	$('#player').height(mainheight);
	$('#player').width(mainwidth);
	$('.container').on("click", function() {
		if (!_ispay) {
			gopay(true)
		}
	});
	if (!isv('vip')) $('#player').on("click", function() {
		try {
			document.getElementById("player").play()
		} catch (e) {}
		if (!_ispay) {
			gopay(true)
		}
	});
	Player.onplay = function() {
		doplay()
	};

	function payout() {
		Player.remove();
		var dia = $.dialog({
			title: '\u6e29\u99a8\u63d0\u793a',
			content: '\u60a8\u7684\u8bd5\u770b\u673a\u4f1a\u7528\u5b8c\u4e86\u007e',
			button: ["\u7b49\u4e0b\u5145", "\u53bb\u5145\u503c"]
		});
		dia.on("dialog:action", function(e) {
			if (e.index == 0) {
				window.location.href = 'javascript:history.back(-1)'
			} else {
				window.location.href = "./check.html?c=" + CID + "&r=" + Math.random()
			}
		})
	}
	function gopay(stop) {
		if (isv('an')) Player.pause();
		else Player.remove();
		var dia = $.dialog({
			title: '\u6e29\u99a8\u63d0\u793a',
			content: '\u975e\u4f1a\u5458\u53ea\u80fd\u89c2\u770b\u0032\u0030\u79d2\u54e6\u007e',
			button: ["\u7b49\u4e0b\u5145", "\u53bb\u5145\u503c"]
		});
		dia.on("dialog:action", function(e) {
			if (e.index == 0) {
				if (stop && isv('an')) Player.play();
				else window.location.href = 'javascript:history.back(-1)'
			} else {
				window.location.href = "./check.html?c=" + CID + "&r=" + Math.random()
			}
		})
	}
	$('#qqvideo-overlay-0,#qqvideobridge').remove()
} else if (_page == "/about.html") {}
Zepto(function($) {
	$('#qqvideo-overlay-0,#qqvideobridge').remove();
	if (browser.versions.weixin || browser.versions.qq) {
		$('.inapptips').show()
	}
	setInterval(getNo, 10000);
	$(".ui-list li,.ui-tiled li").click(function() {
		$(this).data("href") && (location.href = $(this).data("href"))
	});
	$("header .ui-icon-return").click(function() {
		goback()
	});
	$('.toplay').on('click', function() {
		play($(this).attr('title'), $(this).attr('mp4'))
	});
	if (isv('vip')) {
		$('.paytip').html('\u60a8\u5df2\u7ecf\u662f\u0056\u0049\u0050\uff0c\u8bf7\u6b23\u8d4f\uff01')
	} else $('.topay').on('click', function() {
		pay()
	});
	$('header li[data-href]').each(function() {
		l = $(this);
		l.attr('data-href', l.attr('data-href') + "?c=" + CID)
	})
});